import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Home from "../views/Home.vue"
import UserManager from "../views/UserManager.vue"
import ConferenceManager from "../views/ConferenceManager.vue"
import MyConference from "../views/MyConference.vue"
import DataPresentation from "../views/DataPresentation.vue"
import ConferenceInvite from '@/views/ConferenceInvite.vue'
import {show_error_msg} from "../js/msg.js"

const routes = [
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: "/userManager",
    name: 'userManager',
    component: UserManager
  },
  {
    path: "/conferenceManager",
    name: 'conferenceManager',
    component: ConferenceManager
  },
  {
    path: "/myConference",
    name: 'myConference',
    component: MyConference
  },
  {
    path: "/conferenceInvite",
    name: 'conferenceInvite',
    component: ConferenceInvite
  },
  {
    path: "/dataPresentation",
    name: 'dataPresentation',
    component: DataPresentation
  },
  {
    path: "/login",
    name: 'login',
    component: Login
  },
  {
    path: "/",
    name: '',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.afterEach((to, from,next) => {
  //这里路由守卫监控toker是否被清空以及是否尝试跳过登录页面
  if (to.path != "/login" & localStorage.getItem("token") == null) {
    localStorage.clear();
    window.location = "/#/login"
    show_error_msg("安全进程","请先登录系统")
  }
})

export default router
